using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Model
{
    private NetworkManager _networkManager = new NetworkManager();
    public NetworkManager networkManager
    {
        get { return _networkManager; }
    }

    private MsgHandler _msgHandler = new MsgHandler();
    public MsgHandler msgHandler
    {
        get { return _msgHandler; }
    }

    PlayerModel _playerModel = new PlayerModel();
    public PlayerModel playerModel
    {
        get { return _playerModel; }
    }

    RoomModel _roomModel = new RoomModel();
    public RoomModel roomModel
    {
        get { return _roomModel; }
    }
    
    private HeartbeatModel _heartbeatModel = new HeartbeatModel();

    public Model()  
    {
        msgHandler.SetNetworkManager(networkManager);
        networkManager.SetTcpPacketEvent(msgHandler.OnTcpPacket,true);
        networkManager.SetUdpPacketEvent(msgHandler.OnUdpPacket,true);

        _playerModel.Init(networkManager);
        _roomModel.Init(networkManager);
        _heartbeatModel.Init(networkManager);
    }

    private static Model sModel = null;
    public static Model Instance()
    {
        if(null == sModel)
        {
            sModel = new Model();
        }
        return sModel;
    }

    public void Update(float delta)
    {
        _networkManager.Update();
        _heartbeatModel.Update(delta);
    }
}